using Avalonia.Headless;
using Avalonia.Headless.XUnit;
using Avalonia.Controls;
using Avalonia;
using Avalonia.Styling;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using System;
using System.Threading.Tasks;
using Xunit;

namespace AvaloniaUiKit.Tests.UI
{
    public abstract class AvaloniaTestBase : AvaloniaUITestBase
    {
        protected override void OnStartupComplete()
        {
            // 注册UiKitTheme
            Application.Current.Styles.Add(new UiKitTheme
            {
                Mode = ThemeVariant.Light
            });

            base.OnStartupComplete();
        }

        protected T CreateControl<T>(bool attachToRoot = true) where T : Control, new()
        {
            var control = new T();
            
            if (attachToRoot)
            {
                GetMainWindow().Content = control;
            }
            
            Dispatcher.UIThread.RunJobs();
            
            return control;
        }

        protected Window GetMainWindow()
        {
            return (Window)Application.Current.ApplicationLifetime.GetType()
                .GetProperty("MainWindow")
                .GetValue(Application.Current.ApplicationLifetime);
        }
    }
} 